package copy.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import copy.com.JacksonObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.List;
//implements WebMvcConfigurer 由实现转为继承 即避免静态资源自动装配失效
//项目一启动就在加载 到容器中 @Configuration加载bean 随着容器创建而创建



@Configuration
@EnableSwagger2
@EnableKnife4j
public class WebMvcConfig implements WebMvcConfigurer {


    //扩展自己的消息转换器
    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        MappingJackson2HttpMessageConverter messageConverter=new MappingJackson2HttpMessageConverter();
        messageConverter.setObjectMapper(new JacksonObjectMapper());
        converters.add(0, messageConverter);
    }

    //注解是knif4j swagger文档
    @Bean
    public Docket RestApi() {
        //文档类型
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apInfo())
        . select()
                .apis(RequestHandlerSelectors.basePackage("copy.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apInfo() {
        return new ApiInfoBuilder()
                .title("项目名称 {}")
                .version("1.0版本")
                .description("描述信息,集成swagger 测试")
                .build();
    }}
/*@Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        //        registry.addResourceHandler("前端需要处理的访问路径").addResourceLocations("映射到目标资源目录下");
  log.info("这里设置静态资源映射 registry");
        registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
        registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
        //Swagger
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
  //登录退出
                "/employee/login",
                "/employee/logout",
//                "/common/upload",
                //静态
                "/backend/**",
                "/front/**",
                "/user/sendMsg",
                "/user/login",
                "/doc.html",
                "/webjars/**",
                "/swagger-resources",
                "/v2/api-docs"
*/
